" ************ Initialize **************
set nocompatible   
" must be first line
filetype plugin indent on
" automatically detect file types 
syntax on
" syntax highlight

behave mswin

if has('statusline')
	set laststatus=2               
	set statusline=%m%r%h%w\ %l,%c%V%=%<%p%%[b%n][0x%B][len=%L][%{&ff}][%Y]\ %F
endif

" *************** GVIM (here instead .gvimrc) **********
if has('gui_running')
	set guioptions-=T
	" remove toolbar
	set lines=40
	" 40lines instead of 24
	hi cursorline guibg=#333333
endif

" ****************  ENVIRONMENT ********************
set backspace=indent,eol,start
" let backspace over tab, eol, linestart
set showmatch
" show match brackets
set wildmenu	
" show list instead of just completing
set wildmode=list:longest,full
" set wildmenu enables a menu at the bottom of the 
" vim/gvim window.
" The meaning of 'list:longest,full' is so that when you 
" 1 tab  --- show all completion 
" 2 tab  --- show a bar 
set shortmess+=filmnrxoOtT
" abbrev. of messages (avoids 'hit enter')
" eg: longpath fit xxx/.../xxx
set showmode
" display current mode
set incsearch
" find as you type search
" ctrl L / H ---- insert next word of current word
" ctrl R ctrl W --- auto complete 
set hlsearch
" highlight search terms
set autowrite
" automatically save before some commands
set whichwrap=b,s,h,l,<,>,[,]
" This causes the left and right arrow keys
" as well as h and l, to wrap when used at 
" beginning or end of lines (go to last line's end)
set ignorecase
" case insensitive search
set smartcase
" When 'ignorecase' and 'smartcase' are both on, 
" if a pattern contains an uppercase letter, it is 
" case sensitive, otherwise, it is not. 
" For example, /The would find only 'The', while 
" /the would find 'the' or 'The' etc.
set backup
" *** if has('unix')
" *** 	set backupdir=~/.vim/backup
" *** 	set directory=~/.vim/tmp
" *** endif	
" put all *~ file in backupdir !!!!
if version >= 703
	set undofile
endif
	" sv undo history to a file so that you can
	" still undo even after closing a file

if has('win32')
	set backupdir=c:\\vim\\backup//,c:\\vim\\colli//,.
	set directory=C:\\vim\\tmp//,.
	set undodir=C:\\vim\\undo//,.
else
	if  filereadable($HOME.'/.vim/vimrc-etc/init-file-dirs.vim')
		source ~/.vim/vimrc-etc/init-file-dirs.vim
	endif

	" a script to set backupdir, directory, and undodir,
	" making the dirs if they don't already exist.
	" Setting these options ensures that these files won't
	" clutter the working directory
endif
set updatecount=30
" every 30 chars, update the swap file
set writebackup
" backup before overwriting a file
set mouse=a
" Enable the mouse in the console
set textwidth=80
" 80 char limit

if has("autocmd")
	au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" vim jumps to the last position when opening a file

"****************  DISPLAY ******************
set nu
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
 set fileencoding=chinese
else
 set fileencoding=utf-8
endif
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解决consle输出乱码
language messages zh_CN.utf-8

set tabpagemax=15
set winminheight=0
" windows can be 0 line high
set scrolljump=3
" lines to scroll when cursor leaves screen
set nofoldenable
" auto fold code
" set foldmethod=marker      " type of folding
if version >= 703
	set colorcolumn=+1
	" highlights one column past textwidth 
endif

set guifont=Consolas:h13:cANSI
:colorscheme desert

" ************** FORMATTING ******************
set autoindent
" indent at the same level of the previous line
set shiftwidth=2 			" < and > will indepent 2 cols
set tabstop=2 				" 一个tab多少个空格
set expandtab					" turn tabs into spaces 
set softtabstop=2			" when I press 'tab', vim
											" inserts 2 columns
set pastetoggle=<F12>
" pastetoggle (same indentation on pastes)

" *************** GENERAL SHORTCUTS ***********
map Y y$ 
" Y copy to the end of line
map Q gq
" Q reformats the line

" ***************  PLUGINS *****************
autocmd FileType *
			\ if &completefunc != '' |
			\ 	call SuperTabChain(&completefunc, "<c-p>") |
			\		call SuperTabSetDefaultCompletionType("<c-x><c-u>") |
			\ endif


autocmd FileType python setlocal et sta sw=2 sts=2

" Taglist
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
map <F9> :TlistToggle<cr>

" WinManager
let g:winManagerWindowLayout='TagList|FileExplorer'
map <F10> :WMToggle<cr>

"===========  F5 run python ====================
autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
autocmd BufRead *.py nmap <F5> :!python %<CR>

autocmd BufRead *.py set nowrap
autocmd BufRead *.py set go+=b

 
"离开插入模式后自动关闭预览窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
 
"回车即选中当前项
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"
 
"上下左右键的行为
inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up>       pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp>   pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"

